<?php
//tous les mots: trouver le bon mot parmi plusieurs
$titre_page="Activités / version / tous les mots / trouver le bon mot parmi plusieurs";
include("header.inc.php");
$id=$_GET['id'];
$question="SELECT * FROM " .$latable;
$question=mysql_query($question); //finding all words

if(!$question){
	echo "Error mysql: " .mysql_error();
}
$questionN=mysql_num_rows($question); //the number of words

#echo "question: " .$questionOri ." - # " .$questionN ."<hr>"; //tests 

$i=0;

#$goodword=rand(0,$questionN); //creating random number 1 = good word
$goodword=$rand->uRand(1,$questionN); //creating random number 1 = good word

#echo "test; langue = " .$langue ."<br>SQL: " .$questionOri ."<br>urand: " .$goodword;

$goodwordForeign=mysql_result($question,$goodword,'foreign');
$goodwordLocal=mysql_result($question,$goodword,'local');

#$badword1=$goodword;//creating random number 2 = bad word 1
#while ($badword1==$goodword){ //loop until random number 2 is different from random number 1
#$badword1=rand(0,$questionN); // 
$badword1=$rand->uRand(1,$questionN); // 
#}
$badword1Foreign=mysql_result($question,$badword1,'foreign');
$badword1Local=mysql_result($question,$badword1,'local');

$badword2=$badword1;//creating random number 2 = bad word 2
while ($badword2==$badword1){ //loop until random number 2 is different from random number 1
$badword2=rand(0,$questionN); //  
}
$badword2Foreign=mysql_result($question,$badword2,'foreign');
$badword2Local=mysql_result($question,$badword2,'local');

/*
#tests
echo "<br>Random 1 = " .$goodwordForeign ." _ " .$goodwordLocal; //assigning random number 2 = random number 1
echo "<br>Bad word 1 = ".$badword1Foreign ." - " .$badword1Local;
echo "<br>Bad word 2 = ".$badword2Foreign ." - " .$badword2Local;
*/

#definition de l'ordre des reponses (on fait appel a la classe uRand)
$ordre0= $rand->uRand(1,3); 
$ordre1= $rand->uRand(1,3); 
$ordre2= $rand->uRand(1,3); 

/*
echo "<h1>Ordre</h1>";
echo "<div class=\"boite" .$ordre0 ."\">1: " .$ordre0 ."</div>";
echo "<div class=\"boite" .$ordre1 ."\">2: " .$ordre1 ."</div>";
echo "<span class=\"boite" .$ordre2 ."\">3: " .$ordre2 ."</span>";
echo "<hr>";
 */

echo "
<!-- print game -->
<form method=\"get\" name=\"choix_guide\" action=\"govoc.php\">
<input type=\"hidden\" name=\"utilisateur\" value=\"".$utilisateur ."\">
<input type=\"hidden\" name=\"langue\" value=\"".$langue ."\">
<input type=\"hidden\" name=\"goodwordForeign\" value=\"" .$goodwordForeign ."\">
<input type=\"hidden\" name=\"goodwordLocal\" value=\"" .$goodwordLocal ."\">
<table>
<tr><th colspan=\"3\">Que signifie: <b>
".$goodwordForeign;
echo "</b></th></tr><tr>";

#print the answers in the random order (a function would be nicer)
if($ordre0=="1"&&$ordre1=="2"&&$ordre2=="3") { //123
#echo "<td><input type=\"radio\" name=\"answer\" value=\"1\">&nbsp;" .$goodwordLocal ."</input></td>";
echo "<td><input type=\"radio\" name=\"answer\" value=\"1\" onClick=\"document.forms.choix_guide.submit()\">&nbsp;" .$goodwordLocal ."</input></td>";
echo "<td><input type=\"radio\" name=\"answer\" value=\"0\" onClick=\"document.forms.choix_guide.submit()\">&nbsp;" .$badword1Local ."</input></td>";
echo "<td><input type=\"radio\" name=\"answer\" value=\"0\" onClick=\"document.forms.choix_guide.submit()\">&nbsp;" .$badword2Local ."</input></td>";
} elseif($ordre0=="1"&&$ordre1=="3"&&$ordre2=="2") { //132
echo "<td><input type=\"radio\" name=\"answer\" value=\"1\" onClick=\"document.forms.choix_guide.submit()\">&nbsp;" .$goodwordLocal ."</input></td>";
echo "<td><input type=\"radio\" name=\"answer\" value=\"0\" onClick=\"document.forms.choix_guide.submit()\">&nbsp;" .$badword2Local ."</input></td>";
echo "<td><input type=\"radio\" name=\"answer\" value=\"0\" onClick=\"document.forms.choix_guide.submit()\">&nbsp;" .$badword1Local ."</input></td>";
} elseif($ordre0=="2"&&$ordre1=="1"&&$ordre2=="3") { //213
echo "<td><input type=\"radio\" name=\"answer\" value=\"0\" onClick=\"document.forms.choix_guide.submit()\">&nbsp;" .$badword1Local ."</input></td>";	
echo "<td><input type=\"radio\" name=\"answer\" value=\"1\" onClick=\"document.forms.choix_guide.submit()\">&nbsp;" .$goodwordLocal ."</input></td>";
echo "<td><input type=\"radio\" name=\"answer\" value=\"0\" onClick=\"document.forms.choix_guide.submit()\">&nbsp;" .$badword2Local ."</input></td>";
} elseif($ordre0=="2"&&$ordre1=="3"&&$ordre2=="1") { //231
echo "<td><input type=\"radio\" name=\"answer\" value=\"0\" onClick=\"document.forms.choix_guide.submit()\">&nbsp;" .$badword1Local ."</input></td>";	
echo "<td><input type=\"radio\" name=\"answer\" value=\"0\" onClick=\"document.forms.choix_guide.submit()\">&nbsp;" .$badword2Local ."</input></td>";
echo "<td><input type=\"radio\" name=\"answer\" value=\"1\" onClick=\"document.forms.choix_guide.submit()\">&nbsp;" .$goodwordLocal ."</input></td>";
} elseif($ordre0=="3"&&$ordre1=="1"&&$ordre2=="2") { //312
echo "<td><input type=\"radio\" name=\"answer\" value=\"0\" onClick=\"document.forms.choix_guide.submit()\">&nbsp;" .$badword2Local ."</input></td>";
echo "<td><input type=\"radio\" name=\"answer\" value=\"1\" onClick=\"document.forms.choix_guide.submit()\">&nbsp;" .$goodwordLocal ."</input></td>";
echo "<td><input type=\"radio\" name=\"answer\" value=\"0\" onClick=\"document.forms.choix_guide.submit()\">&nbsp;" .$badword1Local ."</input></td>";	
} elseif($ordre0=="3"&&$ordre1=="2"&&$ordre2=="1") { //321
echo "<td><input type=\"radio\" name=\"answer\" value=\"0\" onClick=\"document.forms.choix_guide.submit()\">&nbsp;" .$badword2Local ."</input></td>";
echo "<td><input type=\"radio\" name=\"answer\" value=\"0\" onClick=\"document.forms.choix_guide.submit()\">&nbsp;" .$badword1Local ."</input></td>";	
echo "<td><input type=\"radio\" name=\"answer\" value=\"1\" onClick=\"document.forms.choix_guide.submit()\">&nbsp;" .$goodwordLocal ."</input></td>";
}


include("footer.inc.php");
?>


